package cn.itcast.mapper;

import cn.itcast.pojo.Emp;
import cn.itcast.pojo.LoginInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;


@Mapper
public interface EmpMapper extends BaseMapper<Emp> {


    /*//2.查询所有
    @Select("select e.* , d.name dept_name from emp e left join dept d on e.dept_id = d.id")
    List<Emp> page();

    //3.根据条件查询
    //@Select("select e.*,d.name dept_name from emp e left join dept d on e.dept_id = d.id where e.name like concat('%',#{name},'%') and gender = #{gender} and entry_date between #{begin} and #{end}")
    List<Emp> search(@Param("name") String name, @Param("gender") Integer gender, @Param("begin") LocalDate begin, @Param("end") LocalDate end);


    @Insert("insert into emp (id, username, password, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) values (null,#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Integer addEmp(Emp emp);

    @Select("select * from emp")
    List<Emp> selectAll();

    Integer deleteByIds(@Param("ids") List<Integer> ids);

    @Select("select * from emp where id = #{id}")
    Emp selectById(@Param("id") Integer id);

    //@Update("update emp set name = #{name},password = #{password},username = #{username},gender = #{gender}, image = #{image},dept_id = #{deptId},entry_date = #{entryDate},job = #{job},salary = #{salary} ,create_time = #{createTime},update_time = #{updateTime} where id = #{id};")
    int update(Emp emp);

    Emp selectId(@Param("id") Integer id);

    @Select("select count(*) from emp where dept_id = #{id}")
    Integer selectByDeptIdCount(Integer id);*/

    @Select("select * from emp where username = #{username} and password = #{password}")
    LoginInfo searchUsernameAndPassword(Emp emp);
}
